/*
 * @Author: LuZeng
 * @Date: 2022-08-29 14:05:42
 * @LastEditTime: 2022-09-01 15:52:32
 * @LastEditors: LuZeng
 * @Description: 小白本白，写的不好多多包涵！！！
 * @FilePath: \jsd:\rjiananzhuang\WEB\WEB workspace\lot-music\src\store\userInfo.js
 * 别乱动！
 */
import { getUserSheetAPI } from "@/api/index";
export default {
  namespaced: true,
  actions: {
    // 获取用户歌单
    async getUserSheet(context, value) {
      const res = await getUserSheetAPI({ uid: context.state.userID });
      let arr = res.data.playlist;
      let user = [];
      let star = [];
      arr.forEach((element) => {
        if (element.userId == context.state.userID) {
          user.push(element);
        } else {
          star.push(element);
        }
      });
      user[0].name = "我喜欢的音乐";
      context.commit("updateUserSheet", user);
      context.commit("updateUserStarSheet", star);
    },
    clearInfo(context, value) {
      context.commit("updateUserID", 0);
      context.commit("updateNickName", null);
      context.commit("updateUserImg", null);
      context.commit("updateToken", null);
      context.commit("updateUserSheet", []);
      context.commit("updateUserStarSheet", []);
    },
  },
  mutations: {
    updateUserID(state, value) {
      state.userID = value;
    },
    updateNickName(state, value) {
      state.nickName = value;
    },
    updateUserImg(state, value) {
      state.userImg = value;
    },
    updateToken(state, value) {
      state.token = value;
    },
    updateUserSheet(state, value) {
      state.userSheet = value;
    },
    updateUserStarSheet(state, value) {
      state.userStarSheet = value;
    },
  },
  state: {
    userID: 0,
    nickName: null,
    userImg: null,
    token: null,
    userSheet: [],
    userStarSheet: [],
  },
};
